GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / SetTagAttribute Method / SetTagAttribute(Int32,String,String[]) Method
A unique tag identifier of the tag's tree element to which the new attribute will be attached.
A name of the newly defined attribute to be attached to the specified tag's tree element.
A value of the newly defined attribute as an array of strings, that is to be attached to the specified tag's tree element.
Example





In This Topic
SetTagAttribute(Int32,String,String[]) Method
In This Topic
Creates a new attribute for a structure element (tag) specified by its unique (tag's) identifier, that is a part of the document's tag structure tree related to the currently loaded PDF document.

This attribute consists of a key-value pair: the key is the attribute's name and the value is the attribute's corresponding value. You are allowed to set the attribute's value as an array of strings using this method.

Syntax
'Declaration
 
Public Overloads Function SetTagAttribute( _
   ByVal TagID As Integer, _
   ByVal Key As String, _
   ByVal Value() As String _
) As GdPictureStatus
public GdPictureStatus SetTagAttribute( 
   int TagID,
   string Key,
   string[] Value
)
public function SetTagAttribute( 
    TagID: Integer;
    Key: String;
    Value: Stringarray of
): GdPictureStatus; 
public function SetTagAttribute( 
   TagID : int,
   Key : String,
   Value : String[]
) : GdPictureStatus;
public: GdPictureStatus SetTagAttribute( 
   int TagID,
   string* Key,
   string*[]* Value
) 
public:
GdPictureStatus SetTagAttribute( 
   int TagID,
   String^ Key,
   array<String^>^ Value
) 

Parameters

TagID
A unique tag identifier of the tag's tree element to which the new attribute will be attached.
Key
A name of the newly defined attribute to be attached to the specified tag's tree element.
Value
A value of the newly defined attribute as an array of strings, that is to be attached to the specified tag's tree element.

Return Value

A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

We strongly recommend always checking this status first.

Remarks
This method is only allowed for use with non-encrypted documents.
Example
How to set the border style attribute to a newly created tag attached to the table cell.
Dim caption As String = "Example: SetTagAttribute"
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF()
    Dim message As String = ""
    If (gdpicturePDF.NewPDF(PdfConformance.PDF_UA_1) = GdPictureStatus.OK) AndAlso
       (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        gdpicturePDF.SetTitle("My first PDF/UA document")
        Dim fontResName As String = gdpicturePDF.AddTrueTypeFontU("Arial", False, False, True)
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetTextSize(16) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetLineColor(Color.Black) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetLineWidth(3) <> GdPictureStatus.OK) Then
            message = "Setting text properties has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagRootID As Integer = gdpicturePDF.GetTagRootID()
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The GetTagRootID() method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagTable As Integer = gdpicturePDF.NewTag(tagRootID, "Table")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(Table) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagTableHeader As Integer = gdpicturePDF.NewTag(tagTable, "THead")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(THead) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagTableBody As Integer = gdpicturePDF.NewTag(tagTable, "TBody")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(TBody) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagTableRow As Integer = gdpicturePDF.NewTag(tagTableHeader, "TR")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(TR) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        If (gdpicturePDF.BeginMarkedContent("Artifact") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawLine(100, 100, 300, 100) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFillColor(Color.LightGray) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawRectangle(100, 100, 200, 30, True, False) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "Creating the line/artifact has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim borderStyle As String() = {"None", "Solid", "None", "None"}
        Dim tagTableHeaderData As Integer = gdpicturePDF.NewTag(tagTableRow, "TH")
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetTagAttribute(tagTableHeaderData, "TBorderStyle", borderStyle) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.BeginMarkedContentSequence(tagTableHeaderData, "TH") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFillColor(Color.Black) <> GdPictureStatus.OK) Or
           (gdpicturePDF.DrawTextBox(fontResName, 100, 100, 200, 130, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Header1") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "Creating the first table header cell has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        tagTableHeaderData = gdpicturePDF.NewTag(tagTableRow, "TH")
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetTagAttribute(tagTableHeaderData, "TBorderStyle", borderStyle) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.BeginMarkedContentSequence(tagTableHeaderData, "TH") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFillColor(Color.Black) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawTextBox(fontResName, 200, 100, 300, 130, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Header2") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "Creating the second table header cell has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        tagTableRow = gdpicturePDF.NewTag(tagTableBody, "TR")
        If gdpicturePDF.GetStat() <> GdPictureStatus.OK Then
            message = "The NewTag(TR) method has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        If (gdpicturePDF.BeginMarkedContent("Artifact") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawLine(100, 130, 300, 130) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFillColor(Color.LightGray) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawRectangle(100, 130, 200, 30, True, False) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "Creating the line/artifact has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        Dim tagTableData As Integer = gdpicturePDF.NewTag(tagTableRow, "TD")
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetTagAttribute(tagTableData, "TBorderStyle", borderStyle) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.BeginMarkedContentSequence(tagTableData, "TD") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFillColor(Color.Black) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawTextBox(fontResName, 100, 130, 200, 160, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Data1") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "Creating the first table data cell has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        tagTableData = gdpicturePDF.NewTag(tagTableRow, "TD")
        If (gdpicturePDF.GetStat() <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetTagAttribute(tagTableData, "TBorderStyle", borderStyle) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.BeginMarkedContentSequence(tagTableData, "TD") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.SetFillColor(Color.Black) <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.DrawTextBox(fontResName, 200, 130, 300, 160, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Data2") <> GdPictureStatus.OK) OrElse
           (gdpicturePDF.EndMarkedContent() <> GdPictureStatus.OK) Then
            message = "Creating the second table data cell has failed. Status: " + gdpicturePDF.GetStat().ToString()
            GoTo [error]
        End If
        If gdpicturePDF.SaveToFile("test_tagged.pdf") = GdPictureStatus.OK Then
            message = "The example has been followed successfully and the file has been saved."
        Else
            message = "The example has been followed successfully, but the file can't be saved. Status:" + gdpicturePDF.GetStat().ToString()
        End If
[error]:
        MessageBox.Show(message, caption)
        gdpicturePDF.CloseDocument()
     Else
        MessageBox.Show("The new document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption)
     End If
End Using
string caption = "Example: SetTagAttribute";
using (GdPicturePDF gdpicturePDF = new GdPicturePDF())
{
    string message = "";
    if ((gdpicturePDF.NewPDF(PdfConformance.PDF_UA_1) == GdPictureStatus.OK) &&
        (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
    {
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        // This is required to have a valid PDF_UA document.
        gdpicturePDF.SetTitle("My first PDF/UA document");
        string fontResName = gdpicturePDF.AddTrueTypeFontU("Arial", false, false, true);
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
            (gdpicturePDF.SetTextSize(16) != GdPictureStatus.OK) ||
            (gdpicturePDF.SetLineColor(Color.Black) != GdPictureStatus.OK) ||
            (gdpicturePDF.SetLineWidth(3) != GdPictureStatus.OK))
        {
            message = "Setting text properties has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        int tagRootID = gdpicturePDF.GetTagRootID();
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The GetTagRootID() method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        int tagTable = gdpicturePDF.NewTag(tagRootID, "Table");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(Table) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        int tagTableHeader = gdpicturePDF.NewTag(tagTable, "THead");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(THead) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        int tagTableBody = gdpicturePDF.NewTag(tagTable, "TBody");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(TBody) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        int tagTableRow = gdpicturePDF.NewTag(tagTableHeader, "TR");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(TR) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        if ((gdpicturePDF.BeginMarkedContent("Artifact") != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawLine(100, 100, 300, 100) != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFillColor(Color.LightGray) != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawRectangle(100, 100, 200, 30, true, false) != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "Creating the line/artifact has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        string[] borderStyle = new[] { "None", "Solid", "None", "None" };
        int tagTableHeaderData = gdpicturePDF.NewTag(tagTableRow, "TH");
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
            (gdpicturePDF.SetTagAttribute(tagTableHeaderData, "TBorderStyle", borderStyle) != GdPictureStatus.OK) ||
            (gdpicturePDF.BeginMarkedContentSequence(tagTableHeaderData, "TH") != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFillColor(Color.Black) != GdPictureStatus.OK) |
            (gdpicturePDF.DrawTextBox(fontResName, 100, 100, 200, 130, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Header1") != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "Creating the first table header cell has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        tagTableHeaderData = gdpicturePDF.NewTag(tagTableRow, "TH");
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
            (gdpicturePDF.SetTagAttribute(tagTableHeaderData, "TBorderStyle", borderStyle) != GdPictureStatus.OK) ||
            (gdpicturePDF.BeginMarkedContentSequence(tagTableHeaderData, "TH") != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFillColor(Color.Black) != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawTextBox(fontResName, 200, 100, 300, 130, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Header2") != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "Creating the second table header cell has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        tagTableRow = gdpicturePDF.NewTag(tagTableBody, "TR");
        if (gdpicturePDF.GetStat() != GdPictureStatus.OK)
        {
            message = "The NewTag(TR) method has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        if ((gdpicturePDF.BeginMarkedContent("Artifact") != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawLine(100, 130, 300, 130) != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFillColor(Color.LightGray) != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawRectangle(100, 130, 200, 30, true, false) != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "Creating the line/artifact has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
            
        int tagTableData = gdpicturePDF.NewTag(tagTableRow, "TD");
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
            (gdpicturePDF.SetTagAttribute(tagTableData, "TBorderStyle", borderStyle) != GdPictureStatus.OK) ||
            (gdpicturePDF.BeginMarkedContentSequence(tagTableData, "TD") != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFillColor(Color.Black) != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawTextBox(fontResName, 100, 130, 200, 160, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Data1") != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "Creating the first table data cell has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        tagTableData = gdpicturePDF.NewTag(tagTableRow, "TD");
        if ((gdpicturePDF.GetStat() != GdPictureStatus.OK) ||
            (gdpicturePDF.SetTagAttribute(tagTableData, "TBorderStyle", borderStyle) != GdPictureStatus.OK) ||
            (gdpicturePDF.BeginMarkedContentSequence(tagTableData, "TD") != GdPictureStatus.OK) ||
            (gdpicturePDF.SetFillColor(Color.Black) != GdPictureStatus.OK) ||
            (gdpicturePDF.DrawTextBox(fontResName, 200, 130, 300, 160, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "Data2") != GdPictureStatus.OK) ||
            (gdpicturePDF.EndMarkedContent() != GdPictureStatus.OK))
        {
            message = "Creating the second table data cell has failed. Status: " + gdpicturePDF.GetStat().ToString();
            goto error;
        }
        if (gdpicturePDF.SaveToFile("test_tagged.pdf") == GdPictureStatus.OK)
            message = "The example has been followed successfully and the file has been saved.";
        else
            message = "The example has been followed successfully, but the file can't be saved. Status:" + gdpicturePDF.GetStat().ToString();
        error:
        MessageBox.Show(message, caption);
        gdpicturePDF.CloseDocument();
    }
    else
        MessageBox.Show("The new document can't be created. Status: " + gdpicturePDF.GetStat().ToString(), caption);
}
See Also